package com.ruoyi.project.dict.tag.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.dict.tag.domain.MaterialTag;
import com.ruoyi.project.dict.tag.service.IMaterialTagService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 学习资料标签Controller
 * 
 * @author shixiangwen
 * @date 2020-05-12
 */
@Controller
@RequestMapping("/dict/tag")
public class MaterialTagController extends BaseController
{
    private String prefix = "dict/tag";

    @Autowired
    private IMaterialTagService materialTagService;

    @RequiresPermissions("dict:tag:view")
    @GetMapping()
    public String tag()
    {
        return prefix + "/tag";
    }

    /**
     * 查询学习资料标签列表
     */
    @RequiresPermissions("dict:tag:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MaterialTag materialTag)
    {
        startPage();
        List<MaterialTag> list = materialTagService.selectMaterialTagList(materialTag);
        return getDataTable(list);
    }

    /**
     * 导出学习资料标签列表
     */
    @RequiresPermissions("dict:tag:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MaterialTag materialTag)
    {
        List<MaterialTag> list = materialTagService.selectMaterialTagList(materialTag);
        ExcelUtil<MaterialTag> util = new ExcelUtil<MaterialTag>(MaterialTag.class);
        return util.exportExcel(list, "tag");
    }

    /**
     * 新增学习资料标签
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存学习资料标签
     */
    @RequiresPermissions("dict:tag:add")
    @Log(title = "学习资料标签", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MaterialTag materialTag)
    {
        return toAjax(materialTagService.insertMaterialTag(materialTag));
    }

    /**
     * 修改学习资料标签
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        MaterialTag materialTag = materialTagService.selectMaterialTagById(id);
        mmap.put("materialTag", materialTag);
        return prefix + "/edit";
    }

    /**
     * 修改保存学习资料标签
     */
    @RequiresPermissions("dict:tag:edit")
    @Log(title = "学习资料标签", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MaterialTag materialTag)
    {
        return toAjax(materialTagService.updateMaterialTag(materialTag));
    }

    /**
     * 删除学习资料标签
     */
    @RequiresPermissions("dict:tag:remove")
    @Log(title = "学习资料标签", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(materialTagService.deleteMaterialTagByIds(ids));
    }
}
